<?php 
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Datum in der Vergangenheit
session_start();
?>
<html>
<head>
	<title>DS-Upload</title>
	<link rel="stylesheet" type="text/css" href="../styleBackend.css"/>
	<link rel="stylesheet" type="text/css" href="uploadStyle.css"/>
	<meta name="viewport" content="width=device-width, initial-scale=1.0" /> 
</head>
<body>

<?php

include("uploadFunktionen.php");

//error_reporting(0);

$folder = "";
$path = '../pic/';

if( isset($_SESSION['login']) === false || (isset($_SESSION['login']) !== false && $_SESSION['login'] == "0") ){
	
	echo "<a class=\"backLink\" href='../login.php'>Login-Bereich</a>";
	return;
	
}
	
if( isset($_GET['folder']) ){	
	$folder = $_GET['folder'];
	$path = '../pic/'.$folder."/";
}

if( isset($_POST['folder']) ){	
	$folder = $_POST['folder'];
	$path = '../pic/'.$folder."/";
}

if( isset($_POST['delete']) ){
	echo deletePicWithName($path.$_POST['delete']);
	ordnerAnsicht($path, $folder);
}
else if( isset($_FILES['userfile']) ){
		
	$name = pathinfo(basename($_FILES['userfile']['name']), PATHINFO_FILENAME);
	$extension = pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION);
	$increment = ''; //start with no suffix

	while( file_exists($path.$name.$increment . '.' . $extension) ) {
		$increment++;
	}
	$uploadfile = $path.$name.$increment.'.'.$extension;	
	
	if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
		echo "Datei erfolgreich hochgeladen.<br>";
		echo $uploadfile."<br>";
	} else {
		echo "Error!\n";
		print_r($_FILES);
	}

	ordnerAnsicht($path, $folder);

}
else {
	ordnerAnsicht($path, $folder);
}
	
?>
</body>
</html>